home *** CD-ROM | disk | FTP | other *** search
- class Cannon
- {
- var index;
- var bmpBase;
- var bmpBarrel;
- var bmpExplode;
- var bmpCanvas;
- var position;
- var VEL;
- var energy;
- var frameExp;
- var shotDelay;
- var bOnScreen;
- var bFlash;
- var rotation;
- var screenPos;
- var maxRot = 2.6179938779914944;
- var minRot = 0.5235987755982988;
- function Cannon(pos, type, indexNew)
- {
- this.index = indexNew;
- var _loc2_ = flash.display.BitmapData.loadBitmap("gunTank");
- this.bmpBase = new flash.display.BitmapData(77,56,true,0);
- this.bmpBase.copyPixels(_loc2_,new flash.geom.Rectangle(0,type * 56,77,56),new flash.geom.Point(0,0),null,null,true);
- _loc2_ = flash.display.BitmapData.loadBitmap("gunTankGun");
- this.bmpBarrel = new flash.display.BitmapData(39,24,true,0);
- this.bmpBarrel.copyPixels(_loc2_,new flash.geom.Rectangle(0,type * 24,39,24),new flash.geom.Point(0,0),null,null,true);
- this.bmpExplode = flash.display.BitmapData.loadBitmap("explosion0");
- this.bmpCanvas = Game.bmpDead;
- this.position = pos.clone();
- this.VEL = 10;
- this.energy = 5;
- this.frameExp = 0;
- this.shotDelay = 1;
- this.bOnScreen = false;
- this.bFlash = false;
- }
- function getPosition(Void)
- {
- return this.position.clone();
- }
- function step(chopperPos, chopperVel, aShots)
- {
- if(!this.bOnScreen || this.energy == 0)
- {
- return undefined;
- }
- var _loc4_ = aShots.length;
- var _loc3_ = 0;
- while(_loc3_ < _loc4_)
- {
- var _loc2_ = Shot(aShots[_loc3_]);
- var _loc7_ = _loc2_.position.x - this.position.x;
- var _loc6_ = _loc2_.position.y - (this.position.y - 2);
- if(_loc7_ * _loc7_ + _loc6_ * _loc6_ < 1600)
- {
- Game.getInstance().removeAllyShot(_loc2_);
- this.energy = this.energy - 1;
- this.bFlash = true;
- Game.getInstance().createShrapnel(_loc2_.position);
- if(this.energy == 0)
- {
- Game.getInstance().saveHostileInd(this.index);
- Game.getInstance().addPoints(this.position,200);
- Sounds.playSound("bazooka");
- trace("destroyed");
- }
- break;
- }
- _loc3_ = _loc3_ + 1;
- }
- _loc7_ = chopperPos.x + chopperVel.x * 10 - this.position.x;
- _loc6_ = chopperPos.y + chopperVel.y * 10 - this.position.y;
- this.rotation = Math.atan2(_loc6_,_loc7_);
- if(this.rotation > this.maxRot)
- {
- this.rotation = this.maxRot;
- }
- else if(this.rotation < this.minRot)
- {
- this.rotation = this.minRot;
- }
- if(this.shotDelay-- <= 0)
- {
- this.shotDelay = 40 + Math.round(30 * Math.random());
- var _loc10_ = new flash.geom.Point(this.position.x - 24 + 30 * Math.cos(this.rotation),this.position.y + 52 + 30 * Math.sin(this.rotation));
- var _loc9_ = this.rotation + 3.141592653589793 * Math.round(15 * (1 - 2 * Math.random())) / 180;
- var _loc11_ = new flash.geom.Point(this.VEL * Math.cos(_loc9_),this.VEL * Math.sin(_loc9_));
- var _loc8_ = 20 + Math.round(15 * Math.random());
- _loc8_ = 5 + Math.round(Math.sqrt(_loc7_ * _loc7_ + _loc6_ * _loc6_) / this.VEL) + Math.round(15 * (1 - 2 * Math.random()));
- Game.getInstance().createShot(false,_loc10_,_loc11_,_loc8_);
- Sounds.playSound("gunfire");
- }
- }
- function draw(leftEdge)
- {
- var _loc8_ = this.position.x - leftEdge - this.bmpBase.width / 2;
- var _loc7_ = this.position.y + this.bmpBase.height / 2;
- this.screenPos = new flash.geom.Point(_loc8_,_loc7_);
- if(_loc8_ > (- this.bmpBase.width) * 1 && _loc8_ < Game.screenW)
- {
- this.bOnScreen = true;
- if(this.energy > 0)
- {
- var _loc2_ = new flash.display.BitmapData(this.bmpBarrel.width,this.bmpBarrel.height,true,0);
- _loc2_.copyPixels(this.bmpBarrel,this.bmpBarrel.rectangle,new flash.geom.Point(0,0),null,null,true);
- var _loc3_ = new flash.geom.Matrix();
- _loc3_.translate((- _loc2_.width) / 2,(- _loc2_.height) / 2);
- var _loc6_ = new flash.geom.Matrix();
- _loc6_.rotate(- this.rotation);
- _loc3_.concat(_loc6_);
- var _loc5_ = new flash.geom.Matrix();
- _loc5_.translate(_loc8_ + 14,Game.screenH - (_loc7_ - 4));
- _loc3_.concat(_loc5_);
- var _loc9_ = !this.bFlash ? null : new flash.geom.ColorTransform(0,0,0,0,255,255,255,255);
- this.bmpCanvas.draw(_loc2_,_loc3_,_loc9_,null,null,true);
- var _loc4_ = this.bmpBase.clone();
- if(this.bFlash)
- {
- _loc4_.colorTransform(_loc4_.rectangle,new flash.geom.ColorTransform(0,0,0,0,255,255,255,255));
- }
- this.bmpCanvas.copyPixels(_loc4_,_loc4_.rectangle,new flash.geom.Point(this.screenPos.x,Game.screenH - this.screenPos.y),null,null,true);
- this.bFlash = false;
- }
- else
- {
- _loc8_ = this.position.x - leftEdge;
- _loc7_ = this.position.y;
- this.screenPos = new flash.geom.Point(_loc8_,_loc7_);
- this.drawExplosion(this.screenPos,true);
- }
- }
- else
- {
- this.bOnScreen = false;
- }
- }
- function drawExplosion(pos, bRemove)
- {
- var _loc3_ = _root.attachMovie("explosion2","mcExp",_root.getNextHighestDepth());
- _loc3_.gotoAndStop(this.frameExp + 1);
- var _loc4_ = new flash.geom.Matrix();
- _loc4_.translate(pos.x,Game.screenH - pos.y);
- this.bmpCanvas.draw(_loc3_,_loc4_,null,null,null,true);
- _loc3_.removeMovieClip();
- this.frameExp = this.frameExp + 1;
- if(this.frameExp == 27)
- {
- if(bRemove)
- {
- this.onEndDeadAnim();
- }
- }
- }
- function onEndDeadAnim(Void)
- {
- Game.getInstance().removeHostile(this);
- }
- }
-